package chapter14;

import java.util.Random;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/3/12 17:14
 */
class Initable {
    static final int staticFinal = 47;
    static final int staticFinal2 = ClassInitialization.random.nextInt(1000);

    static {
        System.out.println("Initable init");
    }
}

class Initable2 {
    static int staticNonFinal = 147;

    static {
        System.out.println("Initable2 init");
    }
}

class Initable3 {
    static int staticNonFinal = 74;

    static {
        System.out.println("Initable3 init");
    }
}


public class ClassInitialization {
    public static Random random = new Random(47);

    public static void main(String[] args) throws ClassNotFoundException {
        Class initable = Initable.class;
        System.out.println("after creating initable ref");

        System.out.println(Initable.staticFinal);
        System.out.println(Initable.staticFinal2);
        System.out.println(Initable2.staticNonFinal);
        Class<?> initable3 = Class.forName("chapter14.Initable3");
        System.out.println("after creating initable3 ref");
        System.out.println(Initable3.staticNonFinal);

        Class<?> clazz = ClassInitialization.class;
        clazz.isAssignableFrom(Object.class);
    }
}
